package main

import (
	"fmt"
	"runtime"
	"sync"
)

func main() {
	//检测到没有wg.Done()会出发死锁
	var wg sync.WaitGroup
	wg.Add(1)
	fmt.Println("hello world")
	fmt.Println(runtime.GOMAXPROCS(-1))
	//>1限制并行的goroutine数量
	runtime.GOMAXPROCS(2)
	fmt.Println(runtime.GOMAXPROCS(0))
	fmt.Println(runtime.Version())
	fmt.Println(runtime.NumCPU())
	fmt.Println(runtime.NumGoroutine())

	printMemStats()
	//wg.Wait()

	go func() {
		fmt.Println("开启协程")
		wg.Done()
		//退出当前协程
		runtime.Goexit()

	}()
	wg.Wait()
}

func printMemStats() {
	var m runtime.MemStats
	runtime.ReadMemStats(&m)
	fmt.Printf("Alloc = %v MiB \n", m.Alloc/1024/1024)

}

func exit() {
	fmt.Println("开启协程")
	//runtime.Goexit()
}
